{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "dd25f445",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "w= [3.15636039] b= [0.04433569]\n"
     ]
    }
   ],
   "source": [
    "#项目2-例2-2与例2-3代码\n",
    "\n",
    "#训练模型代码\n",
    "#导入导入numpy与线性回归及梯度下降法模型\n",
    "import numpy as np\n",
    "from sklearn.linear_model import LinearRegression,SGDRegressor\n",
    "\n",
    "\n",
    "#输入训练集数据\n",
    "x=np.array([[100],[113],[90],[89],[60],[70],[50],[45],[55],[78]])\t#房屋面积\n",
    "y=np.array([[301],[324],[285],[296],[200],[260],[300],[120],[180],[245]])\t#售价\n",
    "\n",
    "#建立模型，训练模型\n",
    "model=SGDRegressor(loss='huber',max_iter=5000,random_state=42)\t#建立基于梯度下降法的线性回归模型\n",
    "model.fit(x,y.ravel())\t\t\t\t#开始训练模型\n",
    "\n",
    "#求解线性回归方程参数\n",
    "print(\"w=\",model.coef_,\"b=\",model.intercept_)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "b4f3ec07",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAEHCAYAAACncpHfAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAoxklEQVR4nO3de3hU1b3/8fc3gKQERIoQkUTBomClhUMGpYoiFBQrPdqANcQb2kraR2slXn5W1NKjvXh6GmgfPfZEqXhJSZVIrXeIUC2oaFIUEUREsYmK4WIBI9fM+v2xJiQhEwghM7OT+byeZx5mrz0z+YYk3+/ea6+9ljnnEBGR5JOS6ABERCQxVABERJKUCoCISJJSARARSVIqACIiSUoFQEQkScW0AJhZvpmVmlmqmT1tZm+Z2SPmNWqLZSwiItJQzAqAmR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m8VpcSaTV6JdW5ODOA35iZuHI9rH4ewTWR7YN+HNk9NAI/NDbh4GX8TcydgI+ds7lxjNokYPRKCCRQ2RmtwDvOuf+Wq+tg3Ouxsyeds5NMLOjgf9xzk2p/zxBIYtEpTMAkWYws9uAsZHNAUCVmV0f2X4JeNHMRgMDzGwG8ELcgxQ5RLoGINI8JwJTgDJ8IcgGVuLvVD8RP3/QIiAdeB7YvN/7Ez5FuMj+VABEmqd+X+nD+DmqaoWdcx8DJ0RedzFQDZxjZqX4yds6xytQkeZSF5DIofsTsBsYVttgZkcCV+GnB9kOHAcMdM5tN7POkXWxRQJFZwAih25D5FHfpcBMoAb4eWQ+psfM7AzgTjObFOcYRQ5KZwAizVcM9MXPyhkGMvFnAR865/4XwMymOuecmV2LX71raWQir7+b2SvOuU8SFbzI/lQARJqnI5DjnFtfvzEyhe899ZqOMrOjgFH4JSaJdAP9P2AIoAIggaH7AEREkpSuAYiIJCkVABGRJKUCICKSpFQARESSlAqAiEiSUgEQEUlS/x9UiWd01xLfIAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#绘制图形代码\n",
    "#导入画图工具\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "#求模型预测值\n",
    "y2=model.predict(x)\n",
    "\n",
    "#设置坐标轴\n",
    "plt.xlabel('面积')\t\t\t\t\t\t#图形横轴的标签名称\n",
    "plt.ylabel('售价')\t\t\t\t\t\t#图形纵轴的标签名称\n",
    "plt.rcParams['font.sans-serif']='Simhei'\t#中文文字设置为黑体\n",
    "plt.axis([40,125,100,400])\t\t#设置图像横轴与纵轴的最大值与最小值\n",
    "\n",
    "#绘制并显示图像\n",
    "plt.scatter(x,y,s=60,c='k',marker='o')\t#绘制散点图\n",
    "plt.plot(x,y2,'r-')\t\t\t\t\t#绘制直线，第3个参数表示红色实线\n",
    "plt.legend(['真实值','预测值'])    #显示图例\n",
    "plt.show()\t\t\t\t\t\t\t#显示图像"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "27679111",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "200平方米二手房的预测房价是： 631.3164144744751\n"
     ]
    }
   ],
   "source": [
    "#预测新数据代码\n",
    "a=model.predict([[200]])\n",
    "print(\"200平方米二手房的预测房价是：\",a[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "34b35ec0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "均方误差为： 8694.924125979616\n",
      "均方根误差为： 93.246577020176\n",
      "预测准确率为： 0.9468153562441872\n"
     ]
    }
   ],
   "source": [
    "#评估模型（梯度下降法）\n",
    "#输入测试集\n",
    "x_test=np.array([[103],[115],[90],[89],[60],[70],[50],[45],[55],[78]])\t#房屋面积\n",
    "y_test=np.array([[301],[344],[275],[276],[206],[210],[160],[124],[190],[235]])\t#售价\n",
    "\n",
    "#计算三个值\n",
    "mse=np.average((y2-np.array(y))**2)  #均方误差\n",
    "rmse=np.sqrt(mse)                  #均方根误差\n",
    "r2=model.score(x_test,y_test)     #预测准确率\n",
    "\n",
    "#输出三个值\n",
    "print(\"均方误差为：\",mse)        #输出均方误差\n",
    "print(\"均方根误差为：\",rmse)     #输出均方根误差\n",
    "print(\"预测准确率为：\",r2)         #输出预测准确率\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ca44282a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
